<template>
  <div class="recommend">
     <div class="recommend-head">
      <h3><span>爱情鲜花</span></h3>
     </div>
     <div class="recommend-main">
       <div class="item" v-for = 'item in recommends' :key = 'item.id' @click="clickItem(item.id)">
          <img :src="item.pic" alt="">
          <h4> {{ item.name }} </h4>
          <p> {{ item.minPrice | currency }} </p>
          <!-- 阻止冒泡 -->
          <van-icon name="add" color="#ee0a24" size="30px" @click.stop="addCart(item)" />
       </div>
     </div>
  </div>
</template>

<script>
import { currency } from '@filters'
export default {
  props: {
    recommends: {
      type: Array,
      required: true
    }
  },
  filters: {
    currency
  },
  methods: {
    clickItem (id) {
      this.$emit('click', id)
    },
    // 添加购物车
    addCart (item) {
      this.$emit('clickAddCart', item)
    }
  }
}
</script>

<style lang="scss" scoped>
.recommend{
  .recommend-head{
    display: flex;
    height: 45px;
    font-size: 14px;
    justify-content: center;
    align-items: center;
    span{
       color: #555;
       display: inline-block;
       height: 30px;
       width: 90px;
       text-align: center;
       line-height: 30px;
       border-bottom: 5px solid rgb(136,78,34);
       border-radius: 3px;
    }
  }
  .recommend-main{
    display: flex;
    flex-wrap: wrap;
    .item{
      width: 50%;
      box-sizing: border-box;
      font-size: 16px;
      padding: 10px;
      position: relative;
      img{
        width: 100%;
      }
      h4{
        height: 20px;
        color: #666;
      }
      p{
        height: 20px;
        color: #f43;
      }
      .van-icon{
        position: absolute;
        bottom: 25px;
        right: 20px;
      }
    }
  }
}
</style>
